package com.example.a2048game.diy

import android.content.Context
import android.graphics.Color
import android.util.Log
import android.view.Gravity
import android.widget.FrameLayout
import android.widget.TextView

class Card(context: Context):FrameLayout(context) {

    private var cardNumber:Int=0
    private val label = TextView(context)
    private val lp = LayoutParams(-1,-1)

     fun setCardNumber(cardNumber:Int){
         this.cardNumber=cardNumber
         if (cardNumber<=0)
             label.text=""
         else
             label.text=cardNumber.toString()

         when(cardNumber){
             2->label.setBackgroundColor(Color.RED)
             4->label.setBackgroundColor(Color.YELLOW)
             8->label.setBackgroundColor(Color.GREEN)
             16->label.setBackgroundColor(Color.BLUE)
             32->label.setBackgroundColor(Color.MAGENTA)
             64->label.setBackgroundColor(Color.CYAN)
             128->label.setBackgroundColor(Color.WHITE)
             256->label.setBackgroundColor(Color.GRAY)
             512->label.setBackgroundColor(Color.DKGRAY)
             1024->label.setBackgroundColor(Color.LTGRAY)
             2048->label.setBackgroundColor(Color.BLACK)
             else->label.setBackgroundColor(0x33ffffff)
         }
         label.gravity = Gravity.CENTER

    }
    fun getCardNumber():Int{
        return cardNumber
    }

    /**
     * 比较卡片内容是否相等
     */
     fun equals(card:Card): Boolean {
         return getCardNumber()==card.getCardNumber()
    }

    init {
        label.textSize = 32F
        label.setTextColor(Color.BLACK)
        lp.setMargins(10,10,0,0)
        addView(label,lp)
    }


}